{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6d2fec83",
   "metadata": {},
   "outputs": [],
   "source": [
    "info = {\n",
    "    \"stu1801\":\"ZiQi\",\n",
    "    \"stu1802\":\"XiaoFeng\",\n",
    "    \"stu1803\":\"LiuYu\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1134d075",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1801': 'ZiQi', 'stu1802': 'XiaoFeng', 'stu1803': 'LiuYu'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ecf51fc3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu1801\n",
      "stu1802\n",
      "stu1803\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历是一个字典\n",
    "# i 是 item 在字典循环钟打印的是什么？ key\n",
    "# 我想循环遍历\n",
    "for i in info:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5ef7b05b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu1801 ZiQi\n",
      "stu1802 XiaoFeng\n",
      "stu1803 LiuYu\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历整个字典的 items\n",
    "for k,v in info.items():\n",
    "    print(k,v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9aa9ffa5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践1: stu1801 中取出数字，作为新的字典的key\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[k[3:]] = v\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c76614dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1801': 'ZiQi', '1802': 'XiaoFeng', '1803': 'LiuYu'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "912126d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践2： value 我也想变，所有字母大写\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[k[3:]] = v.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "99e20741",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1801': 'ZIQI', '1802': 'XIAOFENG', '1803': 'LIUYU'}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "65173c92",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践3：让new_info key 由 ‘1801’ => 1801\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[int(k[3:])] = v.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "dd648dac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1801: 'ZIQI', 1802: 'XIAOFENG', 1803: 'LIUYU'}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1fc84a3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
